package com.itjiange;

import com.itjiange.callbehavior.YaCallBehavior;
import com.itjiange.duck.Duck;
import com.itjiange.duck.RedDuck;
import com.itjiange.flybehavior.CanFlyBehavior;

/**
 * 策略模式：定义了算法族，分别封装起来，让它们之间可以互相替换。
 *
 * @author ItJianGe
 * @data 2024/8/15 9:58
 */
public class StrategyMain {
    public static void main(String[] args) {
        Duck redDuck = new RedDuck();
        redDuck.display();
        redDuck.fly();
        redDuck.call();

        System.out.println("\n------------改变后-----------\n");
        redDuck.setFlyBehavior(new CanFlyBehavior()); // 改变算法
        redDuck.setCallBehavior(new YaCallBehavior());

        redDuck.display();
        redDuck.fly();
        redDuck.call();
    }
}